/*
 * <p>Copyright® 2009-2022 东软 IT 实训中心版权所有。</p>
 */

package com.max.back.doctor.service.impl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdcardUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.max.back.doctor.dao.PatientDao;
import com.max.back.doctor.service.PatientService;
import com.max.back.entity.Patient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 辛凤文 forward.seen@foxmail.com
 * @version 1.0
 * @description <p>
 * <code>PatientServiceImpl</code>
 *
 * </p>
 * @time 2022/7/21 23:26
 * @see
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientDao, Patient>
        implements PatientService {

    @Autowired
    private PatientDao patientDao;

    @Override
    public Map<String, Object> getPatientInfoByPatientHistoryId(String patientHistoryId) {
        Patient patient = patientDao.selectNameAndIdentByPatientHistoryId(patientHistoryId);
        String identId = patient.getIdentId();
        Map<String, Object> patientInfo = MapUtil.builder(new HashMap<String, Object>())
                .put("name", patient.getName())
                .put("sex", IdcardUtil.getGenderByIdCard(identId) == 1 ? "男" :
                        "女")
                .put("birth",  IdcardUtil.getYearByIdCard(identId) + "-"
                        + IdcardUtil.getMonthByIdCard(identId) +
                        "-" + IdcardUtil.getDayByIdCard(identId))
                .put("address", IdcardUtil.getProvinceByIdCard(identId)).build();
        return patientInfo;
    }
}